var defaultPageSize = 20;
function getItemHtml(totalCount,pageSize,currPage,id,callback,queryMethod,limitid,inputE){
	return '<a id="_autoPage'+currPage+'" href="#" onclick="javascript:page('+totalCount+','+pageSize+','+currPage+',\''+id+'\',\''+callback+'\',null,\''+queryMethod+'\',\''+limitid+'\','+inputE+')">'+currPage+'</a>';
}
function page(totalCount,pageSize,currPage,id,callback,isfirst,queryMethod,limitid,inputE){
	
	//alert("totalCount"+totalCount+">>pageSize"+pageSize+">>>currPage"+currPage + ">>>id"+id+">>callback"+callback+">>isfirst"+isfirst);
	
	var in_totalCount = parseInt(totalCount);
	var in_pageSize = parseInt(pageSize);
	var in_currPage = parseInt(currPage);
	
	var start = (currPage-1)*pageSize;
	
	if(!isfirst)
		eval(callback+'('+start+','+pageSize+')');
	
	var zz = 5;
	var pagehtml = '';
	var pageCount = Math.ceil(in_totalCount/in_pageSize) ;
	if (pageCount<=1){
		jQuery("#"+id).html(pagehtml);
		return;
	}
	var in_prevPage = in_currPage<=1?1:(in_currPage-1);
	var in_nextPage = in_currPage>=pageCount?pageCount:(in_currPage+1);
	
	
	
	var prevPageHtml = '<a href="#"  onclick="javascript:page('+in_totalCount+','+in_pageSize+','+in_prevPage+',\''+id+'\',\''+callback+'\',null,\''+queryMethod+'\',\''+limitid+'\','+inputE+')">◀上一页</a>';
	var nextPageHtml = '<a href="#"  onclick="javascript:page('+in_totalCount+','+in_pageSize+','+in_nextPage+',\''+id+'\',\''+callback+'\',null,\''+queryMethod+'\',\''+limitid+'\','+inputE+')">下一页▶</a>';

	if(pageCount >= 0 && pageCount<=10 ){
		pagehtml = '';
		for(var i= 1;i<=pageCount;i++){
			pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback,queryMethod,limitid,inputE);
		}
		pagehtml +=(prevPageHtml+nextPageHtml);
	}else if(pageCount> 10){
		if(in_currPage <= (1+zz+1)){
			pagehtml = '';
			for(var i= 1;i<=10;i++){
				pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback,queryMethod,limitid,inputE);
			}
			pagehtml +=('•••'+prevPageHtml+nextPageHtml);
		}else if(in_currPage >= pageCount-zz-1){
			pagehtml = 
				getItemHtml(in_totalCount,in_pageSize,1,id,callback,queryMethod,limitid,inputE)+
				'•••';
			for(var i = pageCount-8;i<=pageCount;i++){
				pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback,queryMethod,limitid,inputE);
			}
			pagehtml +=(prevPageHtml+nextPageHtml);
		}else{
			pagehtml = 
				getItemHtml(in_totalCount,in_pageSize,1,id,callback,queryMethod,limitid,inputE)+
				'•••';
			for(var i = in_currPage-zz;i<=in_currPage+zz;i++){
				pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback,queryMethod,limitid,inputE);//'<a href="#" onclick="javascript:page('+in_totalCount+','+pageSize+','+i+',\''+id+'\')">'+i+'</a>';
			}
			pagehtml +='•••<a href="#" onclick="javascript:page('+in_totalCount+','+in_pageSize+','+pageCount+',\''+id+'\',\''+callback+'\',null,\''+queryMethod+'\',\''+limitid+'\','+inputE+');">'+pageCount+'</a>'+prevPageHtml+nextPageHtml;
		}
		
	}
	//当数据超过一页添加输入框
	if((inputE == undefined || inputE)){
		var pageSizehtml = '<font size="2">每页显示</font>:<input type="text" onblur="chageTotalCount(this.value,\''+queryMethod+'\',\''+limitid+'\')" onkeyup="if(isNaN(this.value)){this.value = \'\';}" style="width:30px;font-size:12px;background-color:#ffffff;padding:3px;" value="'+in_pageSize+'" />';
		pagehtml += pageSizehtml;
	}
	
	
	jQuery("#"+id).html(pagehtml);
	jQuery("a").removeClass('on') ;
	jQuery("#_autoPage"+currPage).addClass('on') ;
}
function funtions(method){
//	this.func = function(){};
//	this.func = eval(method);
	this.func = new Function(method);
}
function chageTotalCount(count,method,limit){
	//alert(method);
	jQuery("#"+limit).val(count);
	var exf = new funtions(method);
	exf.func();
}

//加载动画
var _waiting = {
		_appdiv:function(cont){
			var bodyWidth = document.documentElement.clientWidth;//body对象宽度
			var bodyHeight = document.documentElement.clientHeight;//body高度
			var x = (bodyWidth / 2) - 100;
			var y = (bodyHeight / 2) - 25;
			var divs = document.createElement("DIV");
				divs.setAttribute("id","_wait_page_");
				divs.style.position = "absolute";
				divs.style.display = "block";
				divs.style.zIndex = "811313";
				divs.style.width = "200px";
				divs.style.height = "50px";
				//divs.style.border = "1px solid red";
				//divs.style.backgroundColor = "#ccc";
				divs.style.left = x + "px";
				divs.style.top = y + "px";
			
			var context = "数据正在加载";	
			if(cont)
				context = cont;
			
			if(_waiting._browser == "IE"){
				divs.innerHTML = '<b class="b1"></b><b class="b2 d1"></b><b class="b3 d1"></b><b class="b4 d1"></b>'
					+'<div class="b d1 k" style="text-align:center;verticle-align:middle;line-height:50px;">'+context+'<marquee style="width:15px;" direction="right" scrollamount="2">..</marquee></div><b class="b4b d1"></b><b class="b3b d1"></b><b class="b2b d1"></b><b class="b1b"></b>';
			}else{
				divs.innerHTML = '<b class="b1"></b><b class="b2 d1"></b><b class="b3 d1"></b><b class="b4 d1"></b>'
					+'<div class="b d1 k" style="text-align:center;">'+context+'<marquee style="width:15px;" direction="right" scrollamount="2">..</marquee></div><b class="b4b d1"></b><b class="b3b d1"></b><b class="b2b d1"></b><b class="b1b"></b>';
			}	
			
			document.documentElement.appendChild(divs);
		},
		_show:function(cont){
			if(document.getElementById("_wait_css_div_") == undefined){
			
				var cssDiv = document.createElement("DIV");
					cssDiv.setAttribute("id","_wait_css_div_");
					
				var cssh = '<style type="text/css">'
						+ '.b1,.b2,.b3,.b4,.b1b,.b2b,.b3b,.b4b,.b{display:block;overflow:hidden;}'
						+'.b1,.b2,.b3,.b1b,.b2b,.b3b{height:1px;}'
						+'.b2,.b3,.b4,.b2b,.b3b,.b4b,.b{border-left:1px solid #999;border-right:1px solid #999;}'
						+'.b1,.b1b{margin:0 5px;background:#939393;}'
						+'.b2,.b2b{margin:0 3px;border-width:2px;}'
						+'.b3,.b3b{margin:0 2px;}'
						+'.b4,.b4b{height:2px;margin:0 1px;}'
						+'.d1{background:#ddd;}'
						+'.k {height:45px;}'
						+'</style>';
						
					cssDiv.innerHTML = cssh;	
				document.documentElement.appendChild(cssDiv);	
			}
			this._appdiv(cont);
		},
		_hide:function(){
			var divs = document.getElementById("_wait_page_");
			if(divs != undefined){
			  divs.parentNode.removeChild(divs);
			}
		},
		_browser:function(){
			//判断浏览器/
			return document.all? "IE":"OTHER";
		}
	};